Ext.define('PJ.view.codtrainingprogram.BatchImportEdit', {
    extend: 'AM.default.DefaultWindowForm',
    
    initComponent: function(){
        var me = this;
        me.items = [{
        	xtype: "container",
        	layout: "column",
        	width:380,
        	defaults:{
				labelAlign: 'right',
                labelWidth: 60,
    			allowBlank: true,  //红框是否显示
    			padding: '10 0 0 0'
    		},
        	items:[{
                xtype : 'filefield',
                fieldLabel : "<span style='color:red;'>*</span>上传文件",
                name : 'excelFile',
                width: 360,
                allowBlank: false,
                columnWidth: .9,
                buttonText: '',
                buttonConfig: {
                    iconCls: 'updateIco'
                }
        	}, {
                xtype: 'label',
                html: '导入文件格式为.xls，并且为excel工作薄第一个表单',
                style: 'color:red;',
                margin: '5 0 0 45',
                columnWidth: 1
            }, {
        		xtype: 'hidden',
        		name: 'isUpdate'
        	}]
        }];
        this.buttons = [{
            text: '确定',
            handler: function(button, event){
            	var win = button.up('window');
            	win.sub(win, me.grid);
            }
        }, {
            text: '取消',
            scope: this,
            handler: function(button, event){
				button.up('window').close();
            }
        }];
        me.callParent(arguments);
    },
    sub: function(window, grid){
        var form = window.down("form").getForm();
        var excelFile = form.findField('excelFile');
        var isUpdate = form.findField('isUpdate');
        var filePath = excelFile.getValue();
        var test = filePath.substr(filePath.length - 4);
        var test1 = filePath.substr(filePath.length - 5);
        if (form.isValid()) {
            if (test != ".xls" && test1 != ".xlsx") {
        		Orchid.alert('提示', '请选择以xlsx或xls结尾的文件上传！');
        	}else{
        		form.submit({
        			url: grid.store.importQuotasUrl,
        			params: {},
        			waitMsg: '文件正在上传中，请稍等...',
        			success: function(f, action){
        				Ext.create("AM.default.DefaultWindowView", {
    						title: "提示",
    						height: 140,
    						width: 260,
    						items: [{
    							xtype: 'textareafield',
    							height: 120,
    							width: 240,
    							value: action.result.msg,
    							readOnly: true
    						}],
    						buttons: [{
    							text: '确定',
    							handler: function(){
                					var store = grid.store;
                					var searchCategoryIndex = grid.searchCategoryIndex;
                					var newParams = {
                							searchCateId: searchCategoryIndex
                					};
                					// 4.0强制更改store参数写法
                					var params = grid.getStore().proxy.extraParams;
                					Ext.apply(params, newParams);
                					store.isLoad = true;
                					this.up('window').close();
                					window.close();
                					store.load();
                				}
    						}]
    					});
        			},
        			failure: function(f, action){
        				win1 = Ext.create("AM.default.DefaultWindowView", {
    						title: "错误",
    						height: 200,
    						width: 400,
    						items: [{
    							xtype: 'textareafield',
    							height: 180,
    							width: 380,
    							value: action.result.msg,
    							readOnly: true
    						}],
    						buttons: [{
    							text: '确定',
    							handler: function(){
                					this.up('window').close();
                				}
    						}]
    					});
        			}
        		});
        	}
        }
    }
});
